<?php
$type = isset($this->type) ? $this->type : 'checkbox';
$name = isset($this->name) ? $this->name : 'category_id[]';
$selected = isset($this->selected) ? (array) $this->selected : array();

if(!function_exists('_categoryCheckbox')) {
	function _categoryCheckbox($name, $tree, $ps = array(), $level = 0, $type = 'checkbox') {
		$str = "";
		foreach((array) $tree AS $row) {
			$str .= '<ul class="citem';
			if($level > 0) $str .= ' sub';
			$str .= '">';
			$str .= '<li>';
			$checked = '';
			if(in_array($row['id'], $ps)) {
				$checked = ' checked="checked"';
			}
			$str .= '<input type="' . $type . '" name="' . $name . '" id="__cateogory-' . $row['id'] . '" value="' . $row['id'] . '"' . $checked .' />';
			$str .= '<label class="for-checkbox" for="__cateogory-' . $row['id'] . '">' . $row['title'] . '<em>[' . $row['id'] . ']</em></label>';
			$str .= '</li>';
			if(!empty($row['children'])) {
				$str .= _categoryCheckbox($name, $row['children'], $ps, ($level + 1), $type);
			}
			$str .= '</ul>';
		}
		return $str;
	}
}
echo _categoryCheckbox($name, picture_category::allCategoryToTreeAsArray(), $selected, 0, $type);
?>
